/**
 * 
 */
package com.tanker.common; 


import java.io.Serializable;


public class ResponseObject<T> implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private T data;
	protected String resCode;
	protected String resMsg;
	
	
	
	public ResponseObject(){}
	
	/**
	 * 特殊情况直接返回code，不必返回data，构造responseObject类
	 * @param errorCode 响应编码及响应信息
	 * @author qiang.qian
	 * @time 2015 11 25
	 */
	public ResponseObject(ErrorCode errorCode){
		this.resCode=errorCode.getCode();
		this.resMsg=errorCode.getText();
	}
	
	public ResponseObject(String resCode, String resMsg){
		this.resCode=resCode;
		this.resMsg=resMsg;
	}
	
	/**
	 * 根据错误码和指定返回对象，构造responseObject类
	 * @param errorCode  响应编码及响应信息
	 * @param data       返回的数据
	 */
	public ResponseObject(ErrorCode errorCode,T data)
	{
		this.data=data;
		this.resCode=errorCode.getCode();
		this.resMsg=errorCode.getText();
	}
	
	public ResponseObject(String resCode, String resMsg,T data)
	{
		this.data=data;
		this.resCode=resCode;
		this.resMsg=resMsg;
	}
	
	/**
	 * 构造函数重载
	 * @param outJB
	 */
	@SuppressWarnings("unchecked")
	public ResponseObject(BaseOutJB outJB)
	{
		this.data=(T) outJB.getData();
		this.resCode=outJB.getResCode();
		this.resMsg=outJB.getResMsg();
	}
	
	/**
	 * 根据错误码和指定返回对象，构造responseObject类
	 * @param errorCode  响应编码及响应信息
	 * @param data       返回的数据
	 * @param msg        自定义的响应信息
	 */
	public ResponseObject(ErrorCode errorCode,T data,String msg)
	{
		this.data=data;
		this.resCode=errorCode.getCode();
		this.resMsg=msg;
	}

	/**
	 * 创建一个成功的响应
	 * @param data
	 * @param <T>
	 * @return
     */
	public static <T> ResponseObject<T> createSuccessResponse(T data){
		ResponseObject<T> responseObject = new ResponseObject<T>(ErrorCode.SUCCESS,data);
		return responseObject;
	}
	
	/**
	 * @return the resCode
	 */
	public String getResCode() {
		return resCode;
	}

	/**
	 * @param resCode the resCode to set
	 */
	public void setResCode(String resCode) {
		this.resCode = resCode;
	}

	/**
	 * @return the resMsg
	 */
	public String getResMsg() {
		return resMsg;
	}

	/**
	 * @param resMsg the resMsg to set
	 */
	public void setResMsg(String resMsg) {
		this.resMsg = resMsg;
	}



	/**
	 * @return the data
	 */
	public T getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(T data) {
		this.data = data;
	}
	
	
	/**
	 * 设置响应码与响应信息
	 * @param errorCode
	 */
	public void setErrorCode(ErrorCode errorCode)
	{
		this.resMsg=errorCode.getText();
		this.resCode=errorCode.getCode();
	}

}
